$("#hearder").on("click","img",function(){
	history.go(-1)
})
$("#main").on("click",".order-title-btn",function(){
	var _attr=$(this).attr('_attr');
	location.href="refund.html?_attr="+_attr;
})
var _attr=getUrlParam("_attr")
var obj=$(".order-title-btn");
for(var i=0;i<obj.length;i++){
	if(_attr==obj.eq(i).attr("_attr")){
		obj.eq(i).addClass("thison").siblings("span").removeClass("thison");		
	}
}
var page=1;
getData(_attr,page)
function getData(id,page){
	$.ajax({
        type: "get",
        url: Url + "getRefundReInfo/"+id+"/page/"+page,
        async: false,
        beforeSend: function (xhr) {
            
        },
        success: function (data) {
        	
        	for(var i=0;i<data.countAll.length;i++){
        		for(var j=0;j<$(".order-title-btn").length;j++){
        			if(data.countAll[i].state==$(".order-title-btn").eq(j).attr("_attr")){
        				$(".order-title-btn").eq(j).find("i").text("("+data.countAll[i].count+")")
        				//console.log(data.countAll[i].count(refund_id))
        			}
        		}
        	}
        	
        	if(data.res.length==0){
			         taostr("没有更多了！",1000);
			}
            console.log(data);          
            var str='';
            var msg='';
            var str1='';
            for(var i=0;i<data.res.length;i++){
            	        if ( _attr== 1) {
                            msg = '待审核';  
                            str1='<div class="op-submission" order_num="'+data.res[i].order_number+'">提交审核</div>'	
                        } else if ( _attr== 2) {
                            msg = '审核成功';
                            
                        } else if (_attr== 3) {
                            msg = '审核失败';
                           }
                        else if ( _attr== 4) {
                            msg = '退款成功';                           
                        }
                        else if ( _attr== 5) {
                            msg = '撤销退款';
                                                       
                        }
            	str+='<div class="order-main">'   
				    	+'<a href="orderDetails.html?id='+data.res[i].order_data.order_id+'">'
				    		+'<div class="order-num clear"><span class="order-num-l">订单编号：'+data.res[i].order_number+'</span><span  class="order-num-r">订单状态：'+msg+'</span></div>'
					        +'<div class="order-num clear"><span class="order-num-l">订单总价：'+data.res[i].order_data.total_price+'</span><span  class="order-num-r">提交时间：'+timestampToTime(data.res[i].createtime)+'</span></div>'					       
					        +'<div class="order-price order-num clear">'
					            +'<span class="order-num-l">客户名称：'+data.res[i].nickname+'</span>'   
					            +'<a href="chat.html?id='+data.res[i].user_id+'" class="op-ready">联系客户</a>'				           
					            +str1          
					        +'</div>'				      
				    	+'</a>'			        
				    +'</div>'
            }
            $("#order-main-list").append(str)
        },
        error: function (data,status) {

        },
        complete: function () {

        },
    });
	
}


$(".op-submission").on("click",function(){
	var str='<div class="refunds_reasons">'
		        +'<div class="r_r_box">'
		        	+'<ul>'
		        		+'<li>'
			        		+'<input type="radio" class="radio" onclick="whetherFun(this)" name="browser"  value="1">是'
			        		+'<input type="radio" class="radio" onclick="whetherFun(this)" name="browser"  value="0">否'
		        		+'</li>'
		        		+'<li>退款金额：<br/><input class="input" type="text"/></li>'
		        		+'<li>审核理由：<br/><textarea  class="textarea"></textarea></li>'
		        	+'</ul>'
		        	+'<div>'
		        		+'<a onclick="(function (){$(\'.refunds_reasons\').remove();})()">取消</a>'
		        		+'<a class="submit_a" onclick="submitFun()">提交</a>'
		        	+'</div>'	
		        	+'<input class="order-num-l-input" type="hidden"  value="'+$(this).attr("order_num")+'"/>'
		        +'</div>'
		    +'</div>'
	$("body").append(str)
})
function whetherFun(that) {
	if($(that).val()==0){
		$(that).parents("li").next().hide()
	}else{
		$(that).parents("li").next().show()
	}
}
 function submitFun() {
 		var list= $('input:radio[name="browser"]:checked').val();
        var priceVal= $('.input').val();
        var textareaVal=$('.textarea').val();
        var order_number=$('.order-num-l-input').val();
        var admin_id=4;
        var data={};
            data['order_number']=order_number;
            data['state']=list;
            data['admin_reason']=textareaVal;
            data['refund_fee']=priceVal;
            data['admin_id']=admin_id;
        if(list==1&&priceVal==""){
            taostr("请填写价格!",1000);
            return false;
        }else{
            $.ajax({
                type: "post",
                url: Url + "updateRefund",
                async: false,
                data:data,
                beforeSend: function (xhr) {
                    //xhr.setRequestHeader("token", tokenk);
                },
                success: function (data) {
                    console.log(data);
                    taostr("退款成功！",1000);
                    setTimeout("location.reload()",1000)
                },
                error: function (data,status) {

                },
                complete: function () {

                },
            });
            $('.refunds_reasons').remove();
        }
    }
slideDown("#order-main-list", 0, function (e) {
	var that = this;
	var obj=$(".order-title-btn");
	var id;
	for(var i=0;i<obj.length;i++){
		if(obj.eq(i).hasClass("thison")){
			id=obj.eq(i).attr("_attr")
		}
		
	}
    location.reload();
    that.back.call();

});
slideUp("#order-main-list", 0, function (e) {

    var that = this;
    var obj=$(".order-title-btn");
	var id;
	for(var i=0;i<obj.length;i++){
		if(obj.eq(i).hasClass("thison")){
			id=obj.eq(i).attr("_attr")
		}
	}
    page++;
    getData(id,page)
    that.backup.call();
});
if($(".order-main").length==0){
        $(".discount-main-no").show()
}else{
        $(".discount-main-no").hide()
}
$("#main").on("click",".op-ready",function(){
	var kefu=JSON.parse(storage.getItem("userinfo"));
	if(kefu.user_id==null){
		taostr("此账号暂未开通客服功能！",1000);
		return false;
	}
})